package jasona;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;

import follow_interface.Follow;
import user_interface.User;
import weibo_interface.Weibo;

public class Services {
	public boolean register(String[] userinfo) {
		return User.register(userinfo);
	}

	public boolean uploadHead(String username, String password, byte[] dh) {
		return User.uploadHead(username, password, dh);
	}

	public byte[] getHead(String username, String password) {
		return User.getHead(username, password);
	}

	public ArrayList<String> login(String username, String password) {
		return User.login(username, password);

	}

	public boolean checkUsername(String username) {
		return User.checkUsername(username);
	}

	public boolean checkLogin(String username, String password) {
		return User.checkLogin(username, password);
	}

	public boolean checkUserExist(String username) {
		return !User.checkUsername(username);
	}

	// ////////////////////////////////////////////////////////////////////////////////////
	public String sayHello(String name) {
		return "hello 3" + name;
	}

	public SimpleUser test() {
		SimpleUser a = new SimpleUser();
		a.currentweibo = "lalala";
		return a;
	}

	// ////////////////////////////////////////////////////////////////////////////////////
	public static class SimpleUser {

		public String username = "";
		public String nickname = "";
		public String type = "0";
		public String currentweibo = "";
		public String email = "";
		public byte[] head = null;

		public String getUsername() {
			return this.username;
		}

		public String getNickname() {
			return this.nickname;
		}

		public String getType() {
			return this.type;
		}

		public String getCurrentweibo() {
			return this.currentweibo;
		}

		public String getEmail() {
			return this.email;
		}

		public byte[] getHead() {
			return this.head;
		}

		public String setUsername(String username) {
			return this.username = username;
		}

		public String setNickname(String nickname) {
			return this.nickname = nickname;
		}

		public String setType(String type) {
			return this.type = type;
		}

		public String setCurrentweibo(String currentweibo) {
			return this.currentweibo = currentweibo;
		}

		public String setEmail(String email) {
			return this.email = email;
		}

		public byte[] setHead(byte[] head) {
			return this.head = head;
		}
	}

	public static ArrayList<Services.SimpleUser> getFollow(String username)// rs->username
	{
		return Follow.getFollow(username);
	}

	public static ArrayList<Services.SimpleUser> getbFollow(String username)// username->rs
	{
		return Follow.getbFollow(username);
	}

	public static boolean follow(String username, String busername) {
		return Follow.follow(username, busername);
	}

	public static boolean unfollow(String username, String busername) {
		return Follow.unfollow(username, busername);
	}

	public static boolean checkFollow(String username, String busername) {
		return Follow.checkFollow(username, busername);
	}

	public static boolean checkMutualFollow(String username, String busername) {
		return Follow.checkFollow(username, busername)
				&& Follow.checkFollow(busername, username);
	}

	public static Services.SimpleUser getInfo(String username) {
		return Follow.getInfo(username);
	}

	//////////////////////////////////////////////////////////////////////////////////
	
	public static class WeibomMeta  {



		public String wid = "";
		public String username = "";
		public String content = "";
		public String time = "";
		public int resents = 0;
		public int comments = 0;
		public byte[] img = null;

		public String getContent() {
			return content;
		}

		public void setContent(String content) {
			this.content = content;
		}

		public String getTime() {
			return time;
		}

		public void setTime(String time) {
			this.time = time;
		}

		public int getResents() {
			return resents;
		}

		public void setResents(int resents) {
			this.resents = resents;
		}

		public int getComments() {
			return comments;
		}

		public void setComments(int comments) {
			this.comments = comments;
		}

		public byte[] getImg() {
			return img;
		}

		public void setImg(byte[] img) {
			this.img = img;
		}

		public String getWid() {
			this.generateWid();
			return wid;
		}

		public void setWid(String wid) {
			this.wid = wid;
		}

		public String getUsername() {
			return username;
		}

		public void setUsername(String username) {
			this.username = username;
		}

		public void generateWid() {
			this.wid = Integer
					.toString((this.username + this.content + this.time)
							.hashCode());
		}

		@Override
		public String toString() {
			return this.username + " " + this.content + " " + this.time + " "
					+ this.wid + " " + this.resents + " " + this.comments + " "
					+ this.img;
		}
	}
	
	public static class CommentMeta{

		public String cid = "";
		public String wid = "";
		public String username = "";// (who give comment)
		public String content = "";
		public String time = "";
		public int comment_number = 0;
		public int resend_number = 0;

		public String getCid() {
			//this.generateCid();
			return cid;
		}

		public void setCid(String cid) {
			this.cid = cid;
		}

		public String getWid() {
			return wid;
		}

		public void setWid(String wid) {
			this.wid = wid;
		}

		public String getUsername() {
			return username;
		}

		public void setUsername(String username) {
			this.username = username;
		}

		public String getContent() {
			return content;
		}

		public void setContent(String content) {
			this.content = content;
		}

		public String getTime() {
			return time;
		}

		public void setTime(String time) {
			this.time = time;
		}

		public void generateCid() {
			this.cid = Integer.toString((this.wid + this.content
					+ this.username + this.time).hashCode());
		}

		public int getComment_number() {
			return comment_number;
		}

		public void setComment_number(int comment_number) {
			this.comment_number = comment_number;
		}

		public int getResend_number() {
			return resend_number;
		}

		public void setResend_number(int resend_number) {
			this.resend_number = resend_number;
		}

		@Override
		public String toString() {
			return this.wid + " " + this.cid + " " + this.username + " "
					+ this.content + " " + this.time + " "
					+ this.comment_number;
		}
	}
	
	public static boolean send(Services.WeibomMeta swm) {
		return Weibo.send(swm);
	}
	
	public static boolean comment(Services.CommentMeta scm) {
		return Weibo.comment(scm);
	}
	
	public static ArrayList<Services.WeibomMeta> getWeibos(String username) {
		return Weibo.getWeibos(username);
	}

	public static ArrayList<Services.CommentMeta> getCommnet(String wid) {
		return Weibo.getCommnet(wid);
	}

	public static boolean deleteWeibo(String wid) {
		return Weibo.deleteWeibo(wid);
	}

	public static boolean deleteComment(Services.CommentMeta scm) {
		return Weibo.deleteComment(scm);
	}

	public static ArrayList<Services.WeibomMeta> getBlockCur(
			String[] userlist) {
		return Weibo.getBlockCur(userlist);
	}

	public static boolean resend(Services.WeibomMeta swm, String oriwid,
			int oriresendnumber) {
		return Services.send(swm)
				&& Weibo.resendupdate(oriwid, oriresendnumber);
	}

	public static ArrayList<Services.WeibomMeta> getAllBlock(String[] userlist)
	{
		return Weibo.getAllWeibos(userlist);
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//Services s = new Services();
		//System.out.print(s.checkLogin("liutaojason", "142857000"));
		
		DateFormat df = DateFormat.getDateTimeInstance();
		System.out.print(df.format(new Date()));

		/*
		Services.WeibomMeta swb = new Services.WeibomMeta();
		swb.setUsername("liutaojason3");
		swb.setContent("resend2 first weibo 3+ori");
		swb.setImg(null);
		swb.setResents(0);
		swb.setComments(0);
		swb.setTime(df.format(new Date()));
		swb.generateWid();
		*/
		//System.out.print(Services.resend(swb, "899555931", 1));	
		
		String[] userlist = new String[3];
		userlist[0]=("liutaojason");
		userlist[1]=("liutaojason2");
		userlist[2]=("liutaojason3");
		for (Services.WeibomMeta s : getAllBlock(userlist)) {
			System.out.println(s);
		}
	}
}
